<template>
	<view>
		<TopNav title="饲料库存"></TopNav>
		<SearchMenu @search="handleSearch" @reset="handleReset">
			<template v-slot:search>
				<van-cell title="饲料名称">
					<van-field v-model="queryParams.productName" placeholder="输入饲料名称查询" :border="false"
						input-align="right" class="padding-none" />
				</van-cell>
			</template>
		</SearchMenu>

		<view class="cu-card case">
			<view class="cu-item shadow padding" v-for="item in list" :key="item.id"
				@click="handleToPage('detail',item)">
				<view class="full-width">
					<view class="flex justify-between">
						<view class="full-width text-left overflow-hidden text-cut">
							<text class=" text-bold text-xl text-blue">{{item.name || '-'}}</text>
							<text>（{{item.code}}）</text>
						</view>
						<view class="shrink-0 text-left">
							<text class="text-gray text-width">库存：</text>
							<text>{{item.stock || '0'}}{{item.stockUnit || '-'}}</text>
						</view>
					</view>
					<view class="flex justify-between padding-top-sm">
						<view class="basis-df text-left">
							<text class="text-gray text-width">规格：</text>
							<text>{{item.specifications || '0'}}{{item.specificationsUnitDictName || '-'}}</text>
						</view>
						<view class="basis-df text-left">
							<text class="text-gray text-width">类型：</text>
							<text>{{item.secondTypeDictName || '-'}}</text>
						</view>
					</view>
					<view class="flex justify-between padding-top-sm">
						<view class="basis-df text-left">
							<text class="text-gray text-width">仓库：</text>
							<text>{{item.warehouseName || '-'}}</text>
						</view>

					</view>
				</view>

			</view>
		</view>
		<u-loadmore :status="loadStatus" @loadmore="getMoreList" v-if="list.length" />
		<view class="bottom-tools padding flex justify-around bg-white">
			<van-button class='basis-sm' plain hairline type="info" @click="handleToPage('edit')">新建</van-button>
			<van-button class='basis-sm' plain hairline type="primary" @click="handleToPage('inbound')">入库</van-button>
			<van-button class='basis-sm' plain hairline type="info" @click="handleToPage('outbound')">
				出库
			</van-button>
		</view>
		<van-empty description="暂无数据" v-if="!list.length" />
	</view>
</template>

<script>
	import {
		list
	} from "@/api/work/products-inventory"
	import mixins from "@/mixins"
	export default {
		mixins: [mixins],
		data() {
			return {
				baseUrl: getApp().globalData.config.baseUrl,
				list: [],
				loadStatus: 'loadmore',
				queryParams: {
					startDate: '',
					endDate: '',
					productName: '',
					productTypeDict: 'SL',
					productionBaseId: undefined,
					pageSize: 10,
					pageNum: 1,
				},

			};
		},
		onShow() {
			this.queryParams.productionBaseId = this.$store.state.user.baseInfo.id
			this.getList()
		},
		onReachBottom() {
			if (this.loadStatus === 'nomore') return
			this.queryParams.pageNum += 1
			this.getList()
		},
		methods: {

			getList() {
				list(this.queryParams).then(res => {
					this.listFormat(res)
				})
			},
			getMoreList() {
				this.queryParams.pageNum += 1
				this.getList()
			},
			handleToPage(path, params = {}) {
				switch (path) {
					case 'detail':
						this.$tab.navigateTo('./detail?id=' + params.id)
						break;
					case 'edit':
						this.$tab.navigateTo('./edit')
						break;
					case 'inbound':
						this.$tab.navigateTo('./inbound')
						break;
					case 'outbound':
						this.$tab.navigateTo('./outbound')
						break;
				}
			},
			handleReset(query) {
				this.queryParams = {
					...this.queryParams,
					...query,
					productName: '',
					pageNum: 1
				}
				this.getList()
			},
			handleSearch(query) {
				this.queryParams = {
					...this.queryParams,
					...query,
					pageNum: 1
				}
				this.getList()
			},
		}
	}
</script>

<style lang="scss">
	@import "@/common/var.scss";
	page {
		@include fixed-bottom;
	}

</style>
<style lang="scss" scoped>
	.text-width {
		width: 45px;
		display: inline-block;
	}
</style>
